* 'known': Page is known to exist, so don't check if it does.
* 'broken': Page is known not to exist, so don't check if it does.
* 'noclasses': Don't add any classes automatically (includes "new",
- * "stub", "mw-redirect"). Only use the class attribute provided, if
- * any.
+ * "stub", "mw-redirect", "extiw"). Only use the class attribute
+ * provided, if any, so you get a simple blue link with no funny i-
+ * cons.
* @return string HTML <a> attribute
*/
public function link( $target, $text = null, $customAttribs = array(), $query = array(), $options = array() ) {
}
private function linkUrl( $target, $query, $options ) {
- # If it's a broken link, add the appropriate query pieces. This over-
- # writes the default action!
- if( in_array( 'broken', $options ) ) {
+ # If it's a broken link, add the appropriate query pieces, unless
+ # there's already an action specified.
+ if( in_array( 'broken', $options ) and empty( $query['action'] ) ) {
$query['action'] = 'edit';
$query['redlink'] = '1';
}
- $fragment = $target->getFragmentForURL();
- $title = $target->getPrefixedText();
- # A couple of things to be concerned about here. First of all,
- # getLocalURL() ignores fragments. Second of all, if the Title is
- # *only* a fragment, it returns something like "/".
- if( $fragment === '' and $title !== '' ) {
- return $target->getLocalURL( $query );
- }
- if( $title === '' ) {
- # Just a fragment. There had better be one, anyway, or this is a
- # pretty silly Title.
- return $fragment;
- }
- # Then we must have a fragment *and* some Title text.
- return $target->getLocalURL( $query ) . $fragment;
+ return $target->getLinkUrl( $query );
}
private function linkAttribs( $target, $attribs, $options ) {
}
if( !in_array( 'noclasses', $options ) ) {
- # Now build the classes. This is the bulk of what we're doing.
+ # Now build the classes.
$classes = array();
if( in_array( 'broken', $options ) ) {
- $classes []= 'new';
+ $classes[] = 'new';
+ }
+
+ if( $target->isExternal() ) {
+ $classes[] = 'extiw';
}
# Note that redirects never count as stubs here.
if ( $target->isRedirect() ) {
- $classes []= 'mw-redirect';
+ $classes[] = 'mw-redirect';
} elseif( $target->isContentPage() ) {
+ # Check for stub.
$threshold = $wgUser->getOption( 'stubthreshold' );
if( $threshold > 0 and $target->getLength() < $threshold ) {
- $classes []= 'stub';
+ $classes[] = 'stub';
}
}
if( $classes != array() ) {
return $url;
}
+ /**
+ * Get a URL that's the simplest URL that will be valid to link, locally,
+ * to the current Title. It includes the fragment, but does not include
+ * the server unless action=render is used (or the link is external). If
+ * there's a fragment but the prefixed text is empty, we just return a link
+ * to the fragment.
+ *
+ * @param array $query An associative array of key => value pairs for the
+ * query string. Keys and values will be escaped.
+ * @param string $variant Language variant of URL (for sr, zh..). Ignored
+ * for external links. Default is "false" (same variant as current page,
+ * for anonymous users).
+ * @return string the URL
+ */
+ public function getLinkUrl( $query = array(), $variant = false ) {
+ if( !is_array( $query ) ) {
+ throw new MWException( 'Title::getLinkUrl passed a non-array for '.
+ '$query' );
+ }
+ if( $this->isExternal() ) {
+ return $this->getFullURL( $query );
+ } elseif( $this->getPrefixedText() === ''
+ and $this->getFragment() !== '' ) {
+ return $this->getFragmentForURL();
+ } else {
+ return $this->getLocalURL( $query, $variant )
+ . $this->getFragmentForURL();
+ }
+ }
+
/**
* Get an HTML-escaped version of the URL form, suitable for
* using in a link, without a server name or fragment
!! input
[[MeatBall:SoftSecurity]]
!! result
-<p><a href="http://www.usemod.com/cgi-bin/mb.pl?SoftSecurity" class="extiw" title="meatball:SoftSecurity">MeatBall:SoftSecurity</a>
+<p><a href="http://www.usemod.com/cgi-bin/mb.pl?SoftSecurity" title="meatball:SoftSecurity" class="extiw">MeatBall:SoftSecurity</a>
</p>
!! end
!! input
[[MeatBall:]]
!! result
-<p><a href="http://www.usemod.com/cgi-bin/mb.pl?" class="extiw" title="meatball:">MeatBall:</a>
+<p><a href="http://www.usemod.com/cgi-bin/mb.pl?" title="meatball:" class="extiw">MeatBall:</a>
</p>
!! end
*[[Wikipedia:ro:Olteniţa]]
*[[Wikipedia:ro:Olteniţa]]
!! result
-<ul><li><a href="http://en.wikipedia.org/wiki/ro:Olteni%C5%A3a" class="extiw" title="wikipedia:ro:Olteniţa">Wikipedia:ro:Olteniţa</a>
-</li><li><a href="http://en.wikipedia.org/wiki/ro:Olteni%C5%A3a" class="extiw" title="wikipedia:ro:Olteniţa">Wikipedia:ro:Olteniţa</a>
+<ul><li><a href="http://en.wikipedia.org/wiki/ro:Olteni%C5%A3a" title="wikipedia:ro:Olteniţa" class="extiw">Wikipedia:ro:Olteniţa</a>
+</li><li><a href="http://en.wikipedia.org/wiki/ro:Olteni%C5%A3a" title="wikipedia:ro:Olteniţa" class="extiw">Wikipedia:ro:Olteniţa</a>
</li></ul>
!! end
!! input
[[MeatBall:SoftSecurity#foo]]
!! result
-<p><a href="http://www.usemod.com/cgi-bin/mb.pl?SoftSecurity#foo" class="extiw" title="meatball:SoftSecurity">MeatBall:SoftSecurity#foo</a>
+<p><a href="http://www.usemod.com/cgi-bin/mb.pl?SoftSecurity#foo" title="meatball:SoftSecurity" class="extiw">MeatBall:SoftSecurity#foo</a>
</p>
!! end